package com.dorso.service;
import com.dorso.entity.Product;
import org.springframework.stereotype.Service;

import java.util.*;
@Service
public class ProductService {
    private Map<Long, Product> productMap =
            Collections.synchronizedMap(new HashMap<Long, Product>());

    //添加商品
    public Product addProduct(Product product) {
        productMap.put(product.getId(), product);
        return product;
    }

    //根据id查找
    public Product getProduct(long id) {
        return productMap.get(id);
    }
    //更新产品信息
    public void updateProduct(long id,Product product){
        Product product1=productMap.get(id);
        if(product1!=null){
            productMap.put(product.getId(),product);
        }
    }
    //删除产品
    public void deleteProduct(long id){
        productMap.remove(id);
    }
    public void deleteAll(){
        productMap.clear();
    }
}